package com.jjh.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import com.jjh.common.pojo.InfoEnum;
import com.jjh.common.util.ConstatFinalUtil;
import com.jjh.users.pojo.AStudent;
import com.jjh.users.pojo.ATeacher;

/**
 * 后台的过滤器
 * @author MyJJh
 *
 */
@Component
public class AuthBackInterceptor implements HandlerInterceptor
{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
	{
		ConstatFinalUtil.LOGGER.info("======preHandle======");
		HttpSession session = request.getSession();
		ATeacher teacherSess = (ATeacher) session.getAttribute("TeachersSess");
		AStudent studentSess = (AStudent) session.getAttribute("StudentsSess");
		if(teacherSess != null)
		{
			return true ;
		}else if(studentSess != null)
		{
			return true ;
		}
		/* 返回信息 , 否则白页面 */
		session.setAttribute("info", InfoEnum.INFO_LOGIN_ILLEGAL.getInfo());
		response.sendRedirect(request.getContextPath() + "/login");
		return false ;
	}

}
